//
//  ABHand.m
//  AwesomeAlarm
//
//  Created by Kieraj Mumick on 4/25/14.
//  Copyright (c) 2014 KSM. All rights reserved.
//

#import "ABHand.h"

@implementation ABHand

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}
- (void)drawRect:(CGRect)rect {

    CGPoint const center = self.center;
    CGPoint const top = CGPointMake(center.x, center.y - self.length);
    CGPoint const bottom = CGPointMake(center.x, center.y + self.offsetLength);
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path setLineWidth:self.width];
    [path moveToPoint:bottom];
    [path addLineToPoint:top];
    [self.color set];
    [path stroke];
}

- (void)setDegree:(float)degree {
    [self setDegree:degree animated:NO];
}

- (void)setDegree:(float)degree animated:(BOOL)animated {
    _degree = degree;
    CGAffineTransform const transform = CGAffineTransformMakeRotation(self.degree * M_PI / 180);

    if (animated) {

        [UIView animateWithDuration:1.0
                         animations:^{
                             self.transform = transform;
                         }];
    } else {
        self.transform = transform;
    }
}

@end
